import Vue from 'vue/dist/vue.js'
import App from './App.vue'
import VueRouter from 'vue-router'
import routes from './routes'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
Vue.use(VueRouter)
const router = new VueRouter({
  routes
})
router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  const targetPath = router.history.pending.fullPath;
  if (isChunkLoadFailed) {
    router.replace(targetPath);
  }
});


Vue.config.productionTip = false

new Vue({
    router,
		mounted: function(){
			let matchingView = 'login';
			if (window.localStorage) {
				let homePage = window.localStorage.getItem("homepage");
				if (homePage) {
					matchingView = homePage;
				}
			}
			this.$router.replace({name: matchingView});
		},
		render: h => h(App)
}).$mount('#app')

